Skip to content

docs(coding): add the immutability rule - #373

Merged
daniel-kindl merged 6 commits into
mainfrom
docs/364-immutability
Nov 25, 2026
Merged

daniel-kindl merged 6 commits into
mainfrom
docs/364-immutability

Conversation

@daniel-kindl

Copy link
Copy Markdown
Owner

Closes #364

Summary

coding/immutability.md is the owner page for immutability by default. Before, only the concurrency smell in review-standards named shared mutable state.

  • Declare a variable so that it cannot be reassigned (const, readonly, final, val).
  • Do not change an argument. Return a new value.
  • Make value objects and data transfer types immutable.
  • A declaration that cannot be reassigned does not freeze the content, for example a JavaScript const object.
  • A change in place needs a measurement and stays inside one function or type.

The Enforcement section names ESLint prefer-const, no-param-reassign, typescript-eslint prefer-readonly and the C# readonly and init features.

Evidence

  • Verified: test/immutability.test.mjs came first and failed on all three tests. It pins the key phrases, the examples and the index link. npm run check passes. check:title and check-breaking pass.
  • Unverified: the names of the external lint rules. check-links does not fetch external URLs.
  • Known risk: a consumer review can now report a changed argument as a finding.
  • NOT RUN: actionlint, which runs only in validate.
  • Observability: none, docs only.

Risk and rollback

Low. A new page (MINOR). Revert the commit to roll back.

@daniel-kindl

Copy link
Copy Markdown
Owner Author

Review of PR #373

Verdict: CHANGES-REQUESTED

Head SHA: cab2f19 (one commit, compared with the merge-base of main).

Summary

  • Standards: 0 findings.
  • Specification: 3 Low findings (L1 to L3). Worst: Low.
  • Blast radius: no risk found.
  • Tests: 1 Low finding (L4).

All seven acceptance criteria are met in substance. The findings are small accuracy and test-strength points.

Standards

No findings. Title is a conventional commit under 50 characters. The body links #364 and has Evidence, NOT RUN and Observability lines. npm run check passes.

Specification

  • L1, coding/immutability.md:18-20, Low. Spec: "A good and a bad example" and the page's own rule "Use Readonly<T>, readonly arrays or Object.freeze when the content must not change". The page does not say that Readonly<T> is shallow and compile-time only, and that Object.freeze is shallow. The reader can think Readonly<T> makes a nested value immutable. Rule: writing (no wrong or missing docs). Fix: add one sentence, for example "Both are shallow. Freeze or mark each nested value too."
  • L2, coding/immutability.md:36-37, Low. The good example takes Readonly<Order> and returns "new line totals". Readonly<Order> does not stop order.lines[0].total = x, so the example type hides the same bug that the bad example shows. Fix: use ReadonlyArray for lines in the example, or say Order has readonly fields.
  • L3, coding/immutability.md:15-17, Low. A C# record is only immutable when its properties are init only (the default for positional records). A record with set is mutable. Fix: write "a C# record with init properties".

Blast radius

Safety fact: the change adds one new page, one index line, one CHANGELOG line and one test. No script, workflow or skill reads coding/immutability.md, and check-links passes. Level 4, Run (npm run check exit 0, Node v24.19.0, Linux).

  • Confirmed risk: a consumer review can now report a changed argument. This is the intended effect and the body names it.
  • Cleared: no existing page or skill links the new page, so no old rule changes. MINOR bump is right. test/section-pages.test.mjs and test/rule-owners.test.mjs pass.

Tests

test/immutability.test.mjs pins the heading, the keywords, the two example headings and the index link. I changed the page on purpose and ran the test:

  • Removed "Return a new value", no-param-reassign, Object.freeze, the word "measurement", or the Bad example heading: the test failed, as it should.

  • Changed props: true to props: false: the test did not fail.

  • Changed Readonly<Order> to Order, or broke the performance-testing.md link: the test did not fail. The link is covered by check-links (level 4, npm run check fails for it).

  • L4, test/immutability.test.mjs:60-74, Low. The phrase list does not pin props: true, the prefer-readonly and init names, or frozen=True. The wrong props: false passes. Rule: coding/testing.md. Fix: add props: true, prefer-readonly and init to the list.

The body says the test failed first on all three tests. I cannot check this from one commit (level 1, Stated).

Verification

  • Claims checked against what I know of the tools (level 3, Reasoned, no network fetch): ESLint prefer-const exists. no-param-reassign with props: true also flags property writes on a parameter and does not flag a method call, as the page says. typescript-eslint prefer-readonly checks only private members that are never reassigned. C# 9 init accessors allow assignment only in an initializer. Python @dataclass(frozen=True) blocks field assignment (shallow). A JavaScript const object keeps changeable content. All are correct as written.
  • npm run check in a throwaway checkout of the head: exit 0 (Node v24.19.0, Linux).
  • Required check validate: pass on the head.
  • NOT RUN: actionlint (runs only in validate, which passed). External rule URLs are not fetched.

@daniel-kindl

Copy link
Copy Markdown
Owner Author

Re-review of PR #373

Verdict: CHANGES-REQUESTED

Head SHA: 1173343 (fix commit 9456453, then a merge of main).

Summary

  • Standards: 0 findings.
  • Specification: 1 new Low finding (L5). Worst: Low.
  • Earlier findings: L1, L2, L3 and L4 are fixed.

Earlier findings

  • L1, shallow Readonly<T> and Object.freeze: fixed. coding/immutability.md:20-21 now says "These are shallow" and tells the reader to apply the type or call to each level.
  • L2, good example hid a nested change: fixed. The example uses DeepReadonly<Order> and says it stops a change to order.lines[0].total.
  • L3, C# record needs init: fixed. The page says "a C# record with init properties" and "with set properties is not immutable".
  • L4, weak phrase list: fixed. test/immutability.test.mjs now pins no-param-reassign with props: true, prefer-readonly, init, @dataclass(frozen=True), "These are shallow" and DeepReadonly.

Standards

No findings.

Specification

  • L5, coding/immutability.md:38, Low. The good example uses DeepReadonly<Order>. TypeScript has no built-in DeepReadonly. It is a custom type or a library type (for example from type-fest), and the page does not say so. Spec: "A good and a bad example". A reader can copy the example and get a compile error. Fix: add a clause, for example "DeepReadonly is a custom type that applies readonly to each level", or use Readonly<Order> with ReadonlyArray<Line> and Readonly<Line>.

Blast radius

Safety fact: the delta to the page is wording only, in one new page that nothing reads. The merge of main adds .gitignore and test/gitignore.test.mjs from #363, which this PR does not touch. Level 4, Run: npm run check exit 0 on a throwaway checkout of the head (Node v24.19.0, Linux). No new risk.

Tests

I changed the page on purpose and ran test/immutability.test.mjs:

  • props: true to props: false, prefer-readonly, init, frozen=True, "These are shallow", DeepReadonly and "Return a new value" each removed or changed: the test failed every time. The mutation that survived in the first review (props: false) is now caught.
  • The performance-testing.md link changed to a broken target: the test did not fail. check-links covers it, so this is not a finding.

Verification

  • npm run check on the new head: exit 0 (Node v24.19.0, Linux).
  • Required check validate on this head: pass. NOT RUN: actionlint (runs only in validate, which passed).

@daniel-kindl

Copy link
Copy Markdown
Owner Author

Re-review of PR #373

Verdict: APPROVE-RECOMMENDED

Head SHA: edc27fa

Summary

  • Standards: 0 findings.
  • Specification: 0 findings.
  • Earlier finding L5: fixed. L1 to L4 stay fixed.

Earlier findings

  • L5, DeepReadonly is not a built-in type: fixed. coding/immutability.md:38-41 now says DeepReadonly is a type that makes each nested field readonly and comes from a library or from the project. The test pins the phrase.

Delta

The delta from 1173343 is the L5 edit in 04ce4f4, its test pin in test/immutability.test.mjs:34, and the merge of main with #370 (coding/types.md, its test, and edits to coding/index.md, CHANGELOG.md, CONTRIBUTING.md and two skills). The merge changes no line of coding/immutability.md beyond L5. coding/index.md and CHANGELOG.md keep both the immutability line and the types line.

Blast radius

Safety fact: the L5 edit is wording in a page that nothing reads, and the merged files come unchanged from main. Level 4, Run: npm run check exit 0 on a throwaway checkout of the head (Node v24.19.0, Linux). No new risk.

Tests

The pinned phrase now names the full DeepReadonly sentence. The earlier mutations stay caught by the pins from the previous head. I did not re-run them, because the test file changed only on the one line.

Verification

  • npm run check on the new head: exit 0.
  • Required check validate on this head: pass. NOT RUN: actionlint (runs only in validate, which passed).
  • Main can move before the merge. The merge needs a fresh check on the final head.

@daniel-kindl

Copy link
Copy Markdown
Owner Author

Re-review of PR #373

Verdict: APPROVE-RECOMMENDED

Head SHA: fb60299

Summary

  • Standards: 0 findings.
  • Specification: 0 findings.
  • Earlier findings L1 to L5: fixed (unchanged since edc27fa).

Delta

The delta from edc27fa is the merge of main only (18 files from #370, #374, #375, #376, #378 and #371). The diff against origin/main shows only this PR's 4 files: CHANGELOG.md, coding/immutability.md, coding/index.md and test/immutability.test.mjs. coding/index.md keeps all 14 entries of main and adds the immutability line (15).

Blast radius

Safety fact: after the merge the PR still adds only its 4 files over main, and each other change comes unchanged from main. Level 4, Run: the diff against origin/main at this head.

Verification

  • Required check validate on this head: pass. GitHub shows the merge state CLEAN.
  • I did not re-run npm run check locally. The validate run covers it.
  • NOT RUN: actionlint (runs only in validate, which passed).

@daniel-kindl
daniel-kindl merged commit 9fe306e into main Nov 25, 2026
1 check passed
@daniel-kindl
daniel-kindl deleted the docs/364-immutability branch November 25, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(coding): add the immutability rule

1 participant